package com.bjpowernode.gateway.common.utils;

import jakarta.annotation.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

/**
 * redis工具类
 */
@Component
public class RedisUtil {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    public String getHashValue(String key , String field) {
        return (String) stringRedisTemplate.opsForHash().get(key, field);
    }

    /**
     * no自增
     * @param key
     * @return
     */
    public Long incr(String key) {
        return stringRedisTemplate.opsForValue().increment(key);
    }

    public boolean addList(String key, String value) {
        Long count = stringRedisTemplate.opsForList().leftPush(key, value);
        return count > 0;
    }
}
